﻿#region Copyright
//————————————————————————————————————————//
//	创建人员(Creator)    ：Huangyd
//	创建日期(Date)       ：2012-08-05
//  联系方式(Email)      ：aj-ayumi@163.com; gajayumi@gmail.com; ajayumi@me.com
//  描    述(Description)：
//
//	Copyright (C) 2012 ajayumi 版权所有
//————————————————————————————————————————//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ajayumi.Platform.WinForm.WorkSpace
{
    /// <summary>
    /// 工作空间对象的集合类
    /// </summary>
    public class WorkSpaceCollection : CollectionBase
    {
        public WorkSpaceBase this[int index]
        {
            get
            {
                if (List.Count > index)
                    return List[index] as WorkSpaceBase;
                return null;
            }
        }
        public WorkSpaceBase this[string name]
        {
            get
            {
                var workSpace = (from WorkSpaceBase w in this
                                 where w.Name.Equals(name)
                                 select w).SingleOrDefault<WorkSpaceBase>();
                return workSpace;
            }
        }
        public void Add(WorkSpaceBase value)
        {
            if (!List.Contains(value))
            {
                int count = (from WorkSpaceBase w in this.List
                             where w.Name.Equals(value.Name)
                             select w).Count<WorkSpaceBase>();
                if (count > 0)
                {
                    throw new ArgumentException("请确保WorkSpace名称的唯一性");
                }
                List.Add(value);
            }
        }

        public void Remove(WorkSpaceBase value)
        {
            if (value != null && List.Contains(value))
            { List.Remove(value); }
        }

        public void Remove(string name)
        {
            WorkSpaceBase workspace = this[name];
            this.Remove(workspace);
        }

    }
}
